﻿using Pong.Classes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Text;
using System.Windows.Forms;

namespace Pong
{

    public enum format { small = 1, medium = 2, large = 3, fullScreen = 4 };
    public partial class Home : Form
    {
        private const int POSX_BOXP1 = 123;
        private const int POSY_BOXP1 = 219;

        private const int POSX_BOXP2 = 123;
        private const int POSY_BOXP2 = 256;

        private const int POSX_SIZEBOX = 102;
        private const int POSY_SIZEBOX = 439;

        private const int POSX_GAMEBOX = 102;
        private const int POSY_GAMEBOX = 477;

        private const string STRING_NAME_ERR = "Both players got same nickName, change one please !";

        private LinkedList<String> ListPower { get; set; }
        private LinkedList<String> ListSize { get; set; }

        private LinkedList<String> ListGame { get; set; }

        public ComboBox boxP1;
        public ComboBox boxP2;
        public ComboBox sizeBox;
        public ComboBox gameBox;

        public Boolean isSizeSelected { get; set; }
        public Boolean isGameSelected { get; set; }
        public string NamePlayer1 { get; set; }
        public string NamePlayer2 { get; set; }

        public PowerClass ClassPlayer1 { get; set; }
        public PowerClass ClassPlayer2 { get; set; }
        public int Format { get; set; }

        public Boolean FullScreen = false;

        public string Mode { get; set; }

        public SoundPlayer sp { get; set; }

        public Home()
        {
            InitializeComponent();

            isSizeSelected = false;
            isGameSelected = false;

            ListPower = new LinkedList<string>();
            ListSize = new LinkedList<string>();
            ListGame = new LinkedList<string>();

            ListPower.AddFirst("Ninja");
            ListPower.AddFirst("Shinigami");
            ListPower.AddFirst("Samourai");
            ListPower.AddFirst("Shinobi");

            ListSize.AddFirst("fullScreen");
            ListSize.AddFirst("large");
            ListSize.AddFirst("medium");
            ListSize.AddFirst("small");

            ListGame.AddFirst("survival");
            ListGame.AddFirst("2 players");
            ListGame.AddFirst("1 player");

            this.TbNamePlayer1.Text = "Player1";
            this.TbNamePlayer2.Text = "Player2";
        }

        private void BtnStart_Click(object sender, EventArgs e)
        {


            NamePlayer1 = TbNamePlayer1.Text;
            NamePlayer2 = TbNamePlayer2.Text;

            ClassPlayer1 = createPlayerClass(boxP1.Text, 1);
            ClassPlayer2 = createPlayerClass(boxP2.Text, 2);


            if ((string)(sizeBox.Text) == "fullScreen")
            {
                this.FullScreen = true;
                this.Format = (int)format.medium;
                isSizeSelected = true;
            }
            else if ((string)(this.sizeBox.Text) == "medium")
            {
                this.Format = (int)format.medium;
                isSizeSelected = true;
            }
            else if ((string)(sizeBox.Text) == "small")
            {
                this.Format = (int)format.small;
                isSizeSelected = true;
            }
            else if ((string)(sizeBox.Text) == "large")
            {
                this.Format = (int)format.large;
                isSizeSelected = true;
            }
            else if ((string)(sizeBox.Text) == "")
            {
                this.Format = (int)format.medium;
                isSizeSelected = true;

            }


            if ((string)(gameBox.Text) == "1 player")
            {
                this.Mode = "solo";
                ClassPlayer2 = new Shinobi(2);
                isGameSelected = true;
            }
            else if ((string)(gameBox.Text) == "2 players")
            {
                this.Mode = "multi";
                isGameSelected = true;
            }
            else if ((string)(gameBox.Text) == "survival")
            {
                this.Mode = "survival";
                ClassPlayer2 = new Shinobi(2);
                isGameSelected = true;
            }
            else if ((string)(gameBox.Text) == "")
            {
                this.Mode = "multi";
                isGameSelected = true;

            }

            if (NamePlayer1 == NamePlayer2)
            {
                MessageBox.Show(STRING_NAME_ERR);

            }
            else
            {
                this.Close();
            }


        }

        private void Home_Load(object sender, EventArgs e)
        {

            boxP1 = new ComboBox()
            {
                Name = "CbPowerP1",
                Location = new Point(POSX_BOXP1, POSY_BOXP1)
            };

            foreach (string item in ListPower)
            {
                boxP1.Items.Add(item);

            }

            boxP2 = new ComboBox()
            {
                Name = "CbPowerP2",
                Location = new Point(POSX_BOXP2, POSY_BOXP2)
            };

            foreach (string item in ListPower)
            {
                boxP2.Items.Add(item);

            }

            sizeBox = new ComboBox()
            {
                Name = "CbSize",
                Tag = false,
                Location = new Point(POSX_SIZEBOX, POSY_SIZEBOX)
            };

            foreach (string item in ListSize)
            {
                sizeBox.Items.Add(item);
            }

            gameBox = new ComboBox()
            {
                Tag = false,
                Name = "Cbgame",
                Location = new Point(POSX_GAMEBOX, POSY_GAMEBOX)
            };

            foreach (string item in ListGame)
            {
                gameBox.Items.Add(item);
            }


            this.Controls.Add(boxP1);
            this.Controls.Add(boxP2);
            this.Controls.Add(sizeBox);
            this.Controls.Add(gameBox);
        }

        public PowerClass createPlayerClass(string nameOfClass, int nbPlayer)
        {
            if (nameOfClass == "Samourai")
            {
                return new Samourai(nbPlayer);
            }
            else if (nameOfClass == "Shinobi")
            {
                return new Shinobi(nbPlayer);
            }
            else if (nameOfClass == "Ninja")
            {
                return new Ninja(nbPlayer);
            }
            else if (nameOfClass == "Shinigami")
            {
                return new Shinigami(nbPlayer);
            }
            else
            {
                return new Shinobi(nbPlayer);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string Message = string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13}",
                                             "Welcome to Pong Dojo ! \n",
                                             "Controls : \n ",
                                             "  player 1 : \"Z\" and \"S\" to go up and down \n",
                                             "  player 2 : \"Up\" and \"Down\" to go up and down \n",
                                             "Classes : \n ",
                                             "  Shinobi : he has two more life points than the others\n ",
                                             "  Samourai : he is slower but has a larger paddle \n",
                                             "  Shinigami : he makes his enemy feel disoriented \n",
                                             "  Ninja : he is quicker but has a smaller paddle\n",
                                             "The AI is basically a Shinobi whithout the extra life points \n",
                                             "Gamee modes : \n",
                                             "  Solo : alone against the AI \n",
                                             "  Multi : player vs player \n ",
                                             "  Survival : get the highest score against invincible AI");
            MessageBox.Show(Message);
        }
    }
}
